package dao

import (
	"RestaurantApp/model"
	"github.com/wonderivan/logger"
)

type ShopDao struct {
}

func (this *ShopDao) FindShopByCategoryId(categoryId int) []model.Shop {
	queryWrapper := model.Shop{
		CategoryId: categoryId,
	}
	shops := []model.Shop{}
	err := model.DB.Where(queryWrapper).Find(&shops)
	if err != nil {
		logger.Error(err)
	}
	return shops
}

func (this *ShopDao) FindEveryShop() []model.Shop {
	shops := []model.Shop{}
	err := model.DB.Find(&shops)
	if err != nil {
		logger.Error(err.Error)
	}
	return shops
}

func (this *ShopDao) FindShopByKeyword(keyword string) []model.Shop {
	shops := []model.Shop{}
	err := model.DB.Where("name like ?", "%"+keyword+"%").
		Or("promotion_info like ?", "%"+keyword+"%").
		Find(&shops)
	if err != nil {
		logger.Error(err.Error)
	}
	return shops
}
